package com.dc.bobaoge.project.v2.to.v3.business.core;

import com.dc.bobaoge.base.entity.message.common.po.MessageCommentComplaint;
import com.dc.bobaoge.base.mapper.message.MessageCommentComplaintMapper;
import com.dc.bobaoge.project.base.core.now.mapper.CustomMessageCommentComplaintMapper;
import com.dc.bobaoge.project.base.core.old.mapper.OldCoreMessageCommentReportMapper;
import com.own.business.sync.trigger.base.entity.SyncTrigger;
import com.own.business.sync.trigger.base.method.ResolveMethod;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * MessageCommentComplaintResolveMethod
 *
 * @author chenxueli
 * @date 2023-12-22 19:58:00
 */
@Slf4j
@Component
public class MessageCommentComplaintResolveMethod implements ResolveMethod {

    @Resource
    private MessageCommentComplaintMapper messageCommentComplaintMapper;
    @Resource
    private CustomMessageCommentComplaintMapper customMessageCommentComplaintMapper;
    @Resource
    private OldCoreMessageCommentReportMapper oldCoreMessageCommentReportMapper;

    /**
     * 修改的处理方法
     *
     * @param trigger 日志信息
     */
    @Override
    public void update(SyncTrigger trigger) {
        customMessageCommentComplaintMapper.delete(trigger.getTargetId());
        // 查询评论信息
        var report = oldCoreMessageCommentReportMapper.selectById(trigger.getTargetId());
        if (report == null) {
            throw new RuntimeException("举报信息不存在");
        }
        var complaint = new MessageCommentComplaint();
        complaint.setId(report.getComreportId());
        complaint.setFkCommentId(report.getComreportCommentId());
        complaint.setFkMessageId(report.getComreportMsgId());
        complaint.setComplaintTime(report.getComreportMsgTime());
        complaint.setContent(report.getComreportContent());
        complaint.setFkUserId(report.getComreportUserId());
        complaint.setUserName("");
        complaint.setPhone(report.getUserPhone());
        complaint.setOriginUserId(report.getComreportUserId());
        complaint.setOriginUserName("");
        complaint.setOriginPhone(report.getComreportPhone());
        complaint.setStatus(1);
        messageCommentComplaintMapper.insert(complaint);
    }

    /**
     * 删除的处理方法
     *
     * @param trigger 日志信息
     */
    @Override
    public void delete(SyncTrigger trigger) {
        messageCommentComplaintMapper.deleteById(trigger.getTargetId());
    }

    /**
     * 名称信息
     *
     * @return 名称
     */
    @Override
    public String name() {
        return "message_comment_complaint";
    }

}
